Исходный файл
C:\WINCE600\PLATFORM\COMMON\SRC\X86\COMMON\KITL\pcihelp_x86.c
Модифицированный файл
C:\WINCE600\PLATFORM\PracticeBSP_ARK1370\SRC\COMMON\KITL\pcihelp_x86.c
// //
// Copyright (c) Microsoft Corporation.  All rights reserved. // Copyright (c) Microsoft Corporation.  All rights reserved.
// //
// //
// Use of this sample source code is subject to the terms of the Microsoft // Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If // license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not // you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license, // authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable, // please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation. // see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES. // THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//  File:  id.c //  File:  id.c
// //
//  This file implements helper PCI bus functions. //  This file implements helper PCI bus functions.
// //
#include <windows.h> #include <windows.h>
#include <ceddk.h> #include <ceddk.h>
#include <oal.h> #include <oal.h>
#include <nkintr.h> #include <nkintr.h>
   
ULONG PCIReadBusData(IN ULONG BusNumber, IN ULONG DeviceNumber, IN ULONG FunctionNumber, OUT PVOID Buffer, IN ULONG Offset, IN ULONG Length); ULONG PCIReadBusData(IN ULONG BusNumber, IN ULONG DeviceNumber, IN ULONG FunctionNumber, OUT PVOID Buffer, IN ULONG Offset, IN ULONG Length);
ULONG PCIWriteBusData(IN ULONG BusNumber, IN ULONG DeviceNumber, IN ULONG FunctionNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length); ULONG PCIWriteBusData(IN ULONG BusNumber, IN ULONG DeviceNumber, IN ULONG FunctionNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length);
void printPCIConfig(PCI_COMMON_CONFIG* config); void printPCIConfig(PCI_COMMON_CONFIG* config);
   
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
   
UINT32 OALPCIGetId(UINT32 busId, OAL_PCI_LOCATION pciLoc) UINT32 OALPCIGetId(UINT32 busId, OAL_PCI_LOCATION pciLoc)
{ {
   // stub function - x86 doesn't use this    // stub function - x86 doesn't use this
   return 0;    return 0;
} }
   
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//  Function:  OALPCICfgRead //  Function:  OALPCICfgRead
// //
//  This function reads PCI configuration space at location specified by pciLoc. //  This function reads PCI configuration space at location specified by pciLoc.
//  This routine is hardware dependend and in most cases it will be implemented //  This routine is hardware dependend and in most cases it will be implemented
//  in SoC library or it will platform specific. //  in SoC library or it will platform specific.
// //
UINT32 OALPCICfgRead( UINT32 OALPCICfgRead(
  UINT32 busId, OAL_PCI_LOCATION pciLoc, UINT32 offset, UINT32 size,   UINT32 busId, OAL_PCI_LOCATION pciLoc, UINT32 offset, UINT32 size,
  VOID *pData   VOID *pData
) )
{ {
   OAL_DDK_PARAMS params;    OAL_DDK_PARAMS params;
   
   memset(pData, 0xFF, size);    memset(pData, 0xFF, size);
         
   params.function = IOCTL_OAL_READBUSDATA;    params.function = IOCTL_OAL_READBUSDATA;
   params.rc = 0;    params.rc = 0;
   params.busData.devLoc.BusNumber = busId;    params.busData.devLoc.BusNumber = busId;
   params.busData.devLoc.LogicalLoc = pciLoc.logicalLoc;    params.busData.devLoc.LogicalLoc = pciLoc.logicalLoc;
   params.busData.offset = offset;    params.busData.offset = offset;
   params.busData.length = size;    params.busData.length = size;
   params.busData.pBuffer = pData;    params.busData.pBuffer = pData;
   
   if (!OEMIoControl(    if (!OEMIoControl(
       IOCTL_HAL_DDK_CALL, &params, sizeof(params), NULL, 0, NULL        IOCTL_HAL_DDK_CALL, &params, sizeof(params), NULL, 0, NULL
   ) || !params.rc) return FALSE;    ) || !params.rc) return FALSE;
   
   return params.rc;    return params.rc;
} }
   
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//  Function:  OALPCICfgWrite //  Function:  OALPCICfgWrite
// //
//  This function write PCI configuration space at location specified by pciLoc. //  This function write PCI configuration space at location specified by pciLoc.
//  This routine is hardware dependend and in most cases it will be implemented //  This routine is hardware dependend and in most cases it will be implemented
//  in SoC library or it will be platform specific. //  in SoC library or it will be platform specific.
// //
UINT32 OALPCICfgWrite( UINT32 OALPCICfgWrite(
   UINT32 busId, OAL_PCI_LOCATION pciLoc, UINT32 offset, UINT32 size,    UINT32 busId, OAL_PCI_LOCATION pciLoc, UINT32 offset, UINT32 size,
   VOID *pData    VOID *pData
) )
{ {
   OAL_DDK_PARAMS params;    OAL_DDK_PARAMS params;
   
   params.function = IOCTL_OAL_WRITEBUSDATA;    params.function = IOCTL_OAL_WRITEBUSDATA;
   params.rc = 0;    params.rc = 0;
   params.busData.devLoc.BusNumber = busId;    params.busData.devLoc.BusNumber = busId;
   params.busData.devLoc.LogicalLoc = pciLoc.logicalLoc;    params.busData.devLoc.LogicalLoc = pciLoc.logicalLoc;
   params.busData.offset = offset;    params.busData.offset = offset;
   params.busData.length = size;    params.busData.length = size;
   params.busData.pBuffer = pData;    params.busData.pBuffer = pData;
   
   if (!OEMIoControl(    if (!OEMIoControl(
       IOCTL_HAL_DDK_CALL, &params, sizeof(params), NULL, 0, NULL        IOCTL_HAL_DDK_CALL, &params, sizeof(params), NULL, 0, NULL
   ) || !params.rc) return FALSE;    ) || !params.rc) return FALSE;
   
   return params.rc;    return params.rc;
} }
   
  UCHAR   ucPCIMaxDeviceNumber = PCI_MAX_DEVICES;  
  // -----------------------------------------------------------------------------  
  // -----------------------------------------------------------------------------  
  ULONG  
  PCISetBusDataByOffset(  
                      IN ULONG BusNumber,  
                      IN ULONG SlotNumber,  
                      IN PVOID Buffer,  
                      IN ULONG Offset,  
                      IN ULONG Length  
                      )  
  {  
     PCI_SLOT_NUMBER     slotNumber;  
   
     slotNumber.u.AsULONG = SlotNumber;  
   
     // Since we turn interrupts off in PCIReadBusData/PCIWriteBusData,  
     // we don't need to use CS to serialize the call.  
   
     return (slotNumber.u.bits.DeviceNumber >= ucPCIMaxDeviceNumber)  
         ? 0  
         : PCIWriteBusData (BusNumber, slotNumber.u.bits.DeviceNumber,  
                           slotNumber.u.bits.FunctionNumber, Buffer, Offset, Length);  
  }